// pages/course/courseDetail/courseDetail.js
let app=getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    // 
    shc:false,
    // 课程对象
    course:"",
    // 课程id
    courseId:'',
    // 咨询师id
    consultantId:'',
    // 咨询师对象
    consult:'',
    // 课程评级对象集合
    courseEvaluationList:[],
    // 课堂交流对象集合
    courseTalkList:[],
    // 课堂交流的总条数
    talkTotal:'',
    // 列表顺序
    listCount:1,
    ktjl:1,
    // 课堂交流回复展示状态
    jtt:false,
// 课程交流回复集合
   courseCollectList:[],
    url:'',
    yuLan:'',

  },
  sc(){
   this.setData({
   shc:!this.data.shc
})
  },
check1(){
 this.setData({
  listCount: 1
 })
},
 check3(){
   let that=this
  this.setData({
   listCount: 3
  })
  wx.request({
    method:'get',
    url:that.data.url+'consult/findByIdConsult/'+that.data.consultId,
    success(res){
      console.log(res.data.data)
      that.setData({
        consult:res.data.data
      })
    }
  })
 },
 check4(){
   let that=this
  this.setData({
   listCount: 4
  })
  wx.request({
    method:'get',
    url:that.data.url+'courseTalk/findByCourseIdAndPage',
    data:{
      courseId:that.data.courseId,
      pageNum:1,
      pageSize:3
    },
    success(res){
      console.log(res.data.data)
      that.setData({
        courseTalkList:[...that.data.courseTalkList,...res.data.data.list]
      })

    }
  })
 },
 check5(){
   let that=this
  this.setData({
   listCount: 5
  })
  wx.request({
    method:'get',
    url:that.data.url+'courseEvaluation/findByCourseId?courseId='+that.data.courseId,
    success(res){
      for( let item of res.data.data){
        item.level=new Array(+item.level)
      }
      that.setData({
        courseEvaluationList:res.data.data
      })
    }
  })
 },
 zk(event){
    let that=this
    var  index = event.currentTarget.dataset.index;
    // console.log(event.currentTarget.dataset)
    const  courseTalkId = event.currentTarget.dataset.ctid;
    var courseTalkList=this.data.courseTalkList; 
    // var multiData=event.currentTarget.dataset.multiData;
    // var index=multiData.index;
    // var courseTalkId=multiData.courseTalkId;
    courseTalkList[index].jtt=!courseTalkList[index].jtt
    console.log("id:"+courseTalkId)
   that.setData({
    courseTalkList:courseTalkList
   })
   wx.request({
     url: that.data.url+'courseReply/findByCourseTalkId?courseTalkId='+courseTalkId,
     success(res){
      console.log(res)
      that.setData({
        courseCollectList:res.data.data
      })
    }
   })
  },
 jl1(){
   this.setData({
     ktjl:1
   })
 },
 jl2(){
   this.setData({
     ktjl:2
   })
 },
 jl3(){
   this.setData({
     ktjl:3
   })
 },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.setData({
      url:app.globalData.URL,
      yuLan:app.globalData.downLoad,
      consultId:options.consultId,
      courseId:options.courseId
    })
    let that=this
    wx.request({
      method:'get',
      url:that.data.url+ 'course',
      data:{
        courseId:options.courseId
      },
      success(res){
        // console.log(res.data.data)
        that.setData({
          course:res.data.data
        })
      }
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})